package com.jms.web.controller.jms.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.jms.common.filter.utils.poi.ExcelUtil;
import com.jms.web.controller.jms.domain.AttachFile;
import com.jms.web.controller.jms.service.IAttachFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jms.common.annotation.Log;
import com.jms.common.core.controller.BaseController;
import com.jms.common.core.domain.AjaxResult;
import com.jms.common.enums.BusinessType;
import com.jms.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 附件Controller
 * 
 * @author drx
 * @date 2024-04-29
 */
@RestController
@RequestMapping("/system/file")
public class AttachFileController extends BaseController
{
    @Resource
    private IAttachFileService attachFileService;

    /**
     * 查询附件列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(AttachFile attachFile)
    {
        startPage();
        List<AttachFile> list = attachFileService.selectAttachFileList(attachFile);
        return getDataTable(list);
    }

    /**
     * 查询附件列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:list')")
    @PostMapping("/getList")
    public TableDataInfo getList(@RequestBody AttachFile attachFile)
    {
        startPage();
        List<AttachFile> list = attachFileService.selectAttachFileList(attachFile);
        return getDataTable(list);
    }

    /**
     * 导出附件列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AttachFile attachFile)
    {
        List<AttachFile> list = attachFileService.selectAttachFileList(attachFile);
        ExcelUtil<AttachFile> util = new ExcelUtil<AttachFile>(AttachFile.class);
        util.exportExcel(response, list, "附件数据");
    }

    /**
     * 获取附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(attachFileService.selectAttachFileById(id));
    }

    /**
     * 新增附件
     */
    @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttachFile attachFile)
    {
        return toAjax(attachFileService.insertAttachFile(attachFile));
    }

    /**
     * 修改附件
     */
    @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttachFile attachFile)
    {
        return toAjax(attachFileService.updateAttachFile(attachFile));
    }

    /**
     * 删除附件
     */
    @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(attachFileService.deleteAttachFileByIds(ids));
    }
}
